﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DTO;
using BUS;
namespace TVC_WEB.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UsernameAdmin"] != null)
            {
                Response.Redirect("~/Admin/Page/Categories.aspx");
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            AdminInfo CheckA = new AdminInfo();
            AdminControl adminControl = new AdminControl();
            if (this.txtUsername.Text != "" && this.txtPassword.Text != "")
            {
                CheckA.Username = this.txtUsername.Text.ToString().Trim();
                CheckA.Password = this.txtPassword.Text.ToString().Trim();
                try
                {
                    if (adminControl.CheckLogin(CheckA.Username, CheckA.Password))
                    {
                        Session["UsernameAdmin"] = this.txtUsername.Text;
                        Response.Redirect("~/Admin/Page/Categories.aspx");
                    }
                    else
                    {
                        lblErr.Text = "Kiểm tra lai UserName & Password";
                    }
                }
                catch (Exception ex)
                {
                    lblErr.Text = ex.Message;
                }

            }
            else
            {
                lblErr.Text = "Đăng nhập lại không đươc để trống";
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtUsername.Text = "";
            this.txtPassword.Text = "";
        }
    }
}